﻿package com.singlenotion.events
{
	import flash.events.Event;
	import flash.events.EventDispatcher;

	public class Broadcaster
	{

		private static var eventDispatcher:EventDispatcher;

		/**
		 * Broadcasts an $e to all listeners
		 * To listen to any and all events, use Broadcaster.addEventListener()
		 *
		 * @param	$e		The Event to broadcast
		 * @return			nothing
		 */
		public static function broadcast($e:Event):void
		{
			dispatchEvent($e);
		}
		
		public static function addEventListener($type:String, $listener:Function, $useCapture:Boolean = false, $priority:int = 0, 
												$useWeakReference:Boolean=true):void
		{
			if (!eventDispatcher) eventDispatcher = new EventDispatcher();
			eventDispatcher.addEventListener($type, $listener, $useCapture, $priority, $useWeakReference);
		}

		public static function removeEventListener($type:String, $listener:Function, $useCapture:Boolean=false):void
		{
			if (eventDispatcher) eventDispatcher.removeEventListener($type, $listener, $useCapture );
  	    }
		
		public static function dispatchEvent($e:Event):void
		{
			if (eventDispatcher) eventDispatcher.dispatchEvent($e);
		}

	}
}